<?php
defined("_ALLOW") or die ("Access denied");
?>
<?php
$task = "";
if (isset($_REQUEST['task']))
	$task = $_REQUEST['task'];
else if (isset($_GET['task']))
	$task = $_GET['task'];

?>
<?php
include("components/com_mkuser/toolbar.html.php");
?>
<br />
<div align="center" class="centermain">
<div class="main">
<form action="index.php" method="post" name="adminForm" id="adminForm" >
<?php
switch ($task) {
	case "new":
	case "edit":
		$id = -1;
		$email = "";
		$password = "";
		$hoten = "";
		$dienthoai = "";
		$diachi = "";
		$congty = "";
		$website = "";
		$vip = 0;
		$msgtask = "New";
		$msgtitle = "";
		if ($task == "edit") {
			include_once ("../class/cmkuser.php");
			$id = $_GET['id'];
			$objmkuser = $objmkuser->DocId($id);
			$email = $objmkuser->email;
			$password = $objmkuser->password;
			$hoten = $objmkuser->hoten;
			$dienthoai = $objmkuser->dienthoai;
			$diachi = $objmkuser->diachi;
			$congty = $objmkuser->congty;
			$website = $objmkuser->website;	
			$vip = $objmkuser->vip;		
						
			$msgtask = "Edit";
			$msgtitle = "[" . $hoten . "]";
		}
?>
<script language="javascript" type="text/javascript">
function submitbutton(pressbutton) {
	var form = document.adminForm;
	if (pressbutton == 'cancel') {
		submitform( pressbutton );
		return;
	}
	var hoten = form.hoten.value;
	form.hoten.value = trim(hoten);
	hoten = form.hoten.value;
	if (hoten == "") {
		alert("Vui lòng nhập họ tên ");
		return;
	}
	var email = form.email.value;
	email = trim(email);
	if(email == ""){
		alert("Vui lòng nhập email");
		return;
	}
		
	else {
		submitform(pressbutton);
	}
}
</script>
<table class="adminheading">
		<tr>
			<th class="sections">
			Advertisement:
			<small>
			<?php echo $msgtask; ?>
			</small>
			<small><small>
			<?php echo $msgtitle; ?>
			</small></small>
			</th>
		</tr>
	  </table>

		<table width="100%">
		<tr>
			<td valign="top" width="60%">
				<table class="adminform">
				<tr>
					<th colspan="3">
					Customer Details
				    <input name="id" id="id" type="hidden" value="<?php echo $id; ?>" /></th>
				<tr>	
				<tr>
					<td width="8%">Email</td>
					<td colspan="2">
					<input name="email" type="text" class="text_area" id="email" value="<?php echo $email; ?>" size="50" maxlength="255" />					</td>
				</tr>	
				<tr>
					<td>
					Password</td>
					<td colspan="2">
					<input name="password" type="text" class="text_area" id="password"  size="50" maxlength="255" />					</td>
				</tr>		
				<tr>
					<td width="8%">Username</td>
					<td colspan="2">
					<input name="hoten" type="text" class="text_area" id="hoten" value="<?php echo $hoten; ?>" size="50" maxlength="255" />					</td>
				</tr>
				
				  <tr>
					<td width="8%">Phone</td>
					<td colspan="2">
					<input name="dienthoai" type="text" class="text_area" id="dienthoai" value="<?php echo $dienthoai; ?>" size="50" maxlength="255" />					</td>
				</tr>
				<tr>
					<td width="8%">Address</td>
					<td colspan="2">
					<input name="diachi" type="text" class="text_area" id="diachi" value="<?php echo $diachi; ?>" size="50" maxlength="255" />					</td>
				</tr>
				<tr>
					<td width="8%">Company</td>
					<td colspan="2">
					<input name="congty" type="text" class="text_area" id="congty" value="<?php echo $congty; ?>" size="50" maxlength="255" />					</td>
				</tr>
				<tr>
					<td width="8%">Website</td>
					<td colspan="2">
					<input name="website" type="text" class="text_area" id="website" value="<?php echo $website; ?>" size="50" maxlength="255" />					</td>
				</tr>
				<tr>
					<td width="8%">VIP</td>
					<td colspan="2"><input name="vip" type="text" class="text_area" id="vip" value="<?php echo $vip; ?>" size="2" maxlength="50" /> <strong>(1: VIP)</strong></td>
				</tr>
			</table>
		  </td>
		  </tr>
		</table>
<?php
		break;
	case "order":
	case "remove":
	case "save":
		include_once ("../class/cmkuser.php");
		if ($task=="remove") {
			if (isset($_REQUEST['cid'])) {
				$arrayid = $_REQUEST['cid'];
				$count = count($arrayid);
				for ($i=0; $i<$count; $i++) {
					$sid = $arrayid[$i];
					$objmkuser = $objmkuser->DocId($sid);
					$objmkuser->Xoa();
				}
			}
		}
		else if ($task=="save") {
			$objmkuser->DocForm();
			$objmkuser->Register();
		}
		
		$task = "";
?>
<?php
	default:
?>
<script language="javascript" src="../common/js/checknumber.js">
</script>
<table class="adminheading">
		<tr>
			 <th class="sections">
			Customer Manager
			</th>
		</tr>
</table>
<table class="adminlist">
	<tr>
		<th width="20" nowrap="nowrap">#</th>
		<th width="65%" nowrap="nowrap" class="title">Customer Name</th>
		<th nowrap="nowrap">Customer ID</th>
	</tr>
	<?php
	include_once ("../class/cmkuser.php");
	$array = $objmkuser->Fill("");	
	if (is_array($array)) {
		$indexrow = 0;
		$count = count($array);
		for ($i=0; $i<$count; $i++) {
			$objmkuser = $array[$i];
			$link = "index.php?module=com_mkuser&task=edit&id=" .$objmkuser->id;
	?>
	<tr class="<?php echo "row$indexrow"; ?>">
		<td><input type="checkbox" name="cid[]" value="<?php echo $objmkuser->id; ?>" onclick="isChecked(this.checked);" /></td>
		<td><a href="<?php echo $link; ?>"><?php echo $objmkuser->email; ?> </a></td>
		
		<td align="center"><input type="text" name="id[]" size="5" value="<?php echo $objmkuser->id; ?>" readonly class="text_area" style="text-align: center;" /></td>
	</tr>
	<?php
			$indexrow = 1 - $indexrow;
		}
	}
	?>
</table>
<?php
	break;
}
?>
  <input name="module" type="hidden" id="module" value="com_mkuser">
  <input name="boxchecked" type="hidden" id="boxchecked" value="0" />
  <input name="task" type="hidden" id="task" value="<?php echo $task; ?>" />
</form>
</div></div>
</td></tr>
</table>